package io.renren.modules.generator.controller;

import java.util.List;
import java.util.Map;

import io.renren.modules.generator.entity.SheeppriceEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.NppEntity;
import io.renren.modules.generator.service.NppService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * NPP数据管理
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-04-18 17:30:13
 */
@RestController
@RequestMapping("npp")
public class NppController {
	@Autowired
	private NppService nppService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("npp:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<NppEntity> nppList = nppService.queryList(query);
		int total = nppService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(nppList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{nppId}")
	@RequiresPermissions("npp:info")
	public R info(@PathVariable("nppId") Integer nppId){
		NppEntity npp = nppService.queryObject(nppId);
		
		return R.ok().put("npp", npp);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("npp:save")
	public R save(@RequestBody NppEntity npp){
		nppService.save(npp);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("npp:update")
	public R update(@RequestBody NppEntity npp){
		nppService.update(npp);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("npp:delete")
	public R delete(@RequestBody Integer[] nppIds){
		nppService.deleteBatch(nppIds);
		
		return R.ok();
	}


	@RequestMapping("/yearlist")
	@RequiresPermissions("npp:list")
	public R timelist(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);

		List<NppEntity> nppList = nppService.yearList(query);
		int total = nppService.yearTotal(query);

		PageUtils pageUtil = new PageUtils(nppList, total, query.getLimit(), query.getPage());

		return R.ok().put("page", pageUtil);
		//return R.ok(starttime);
	}
}
